package cn.le.agent;

/**
 * 使用模板方法设计模式,限制泛型类型
 */
public abstract class GenericWithCreate<T> {

     T element;

     GenericWithCreate()
     {
         System.out.println("GenericWithCreate create");
         element = create();
         System.out.println(1);
     }

    abstract  T create();

}

class X{}

class Creator extends  GenericWithCreate<X>{

    X create()
    {
        System.out.println("Creator create");
        return new X();
    }

    void f()
    {
        //返回源代码中给出的底层类的简称。
        System.out.println(element.getClass().getSimpleName());
    }
}

class CreatorGeneric{

    public static void main(String[] args) {

        Creator c = new Creator();
        c.f();

    }
}

